const fs = require("fs");
const upload = (req, res) => {
  const file = req.file;
  console.log(file);
  const suffix = file.mimetype.split("/")[1]; // 获取文件后缀
  const filename = req.file.filename + "." + suffix; // 拼接后缀

  fs.rename(file.path, "uploads/" + filename, (err) => {
    // 重命名文件
    if (err) console.log(err);
  });
  res.send({
    status: "ok",
    url: "/" + filename, // 返回图片URL
  });
};
module.exports = upload;
